import { createApp } from "vue";
import { createPinia } from "pinia";
import ElementPlus from 'element-plus';
import * as ElementPlusIconsVue from '@element-plus/icons-vue';
import 'element-plus/dist/index.css';

import "./styles/index.scss";
import "./permission";
import App from "./App.vue";
import router from "./router";
import { errorHandler } from "./error";
import { useAuthStore } from "./store/modules/auth";
import "./utils/hackIpcRenderer";

const app = createApp(App);
const store = createPinia();

// 注册Element Plus
app.use(ElementPlus);

// 注册Element Plus图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component);
}

app.use(store);
app.use(router);
errorHandler(app);

// 初始化认证状态
const authStore = useAuthStore();
authStore.initializeAuth();

console.log('应用初始化完成:', {
  isLoggedIn: authStore.isLoggedIn,
  userType: authStore.userType,
  userName: authStore.userName
});

app.mount("#app");
